1 using UnityEngine;
2 using System.Collections;
3 using System;
4
5 public class Scaler : MonoBehaviour {
6
7 public IEnumerator IEScaleBy(float startAfter, GameObject go, float speed, float scaleBy) {
8 yield return new WaitForSeconds(startAfter);
9
10 float t = Time.deltaTime * speed;
11 float scale = 1f;
12 float diffScale = scaleBy - scale;
13 Vector3 origScale = go.transform.localScale;
14 while(t < Mathf.PI / 2) {
15 t += Time.deltaTime * speed;
16 go.transform.localScale = origScale * (scale + diffScale * Mathf.Sin(t));
17 yield return null;
18 }
19 go.transform.localScale = origScale * scaleBy;
20 }
21
22 public IEnumerator IEScaleIn(float startAfter, GameObject go, float speed, float endScale) {
23 yield return new WaitForSeconds(startAfter);
24 go.tag = "Busy";
25 float t = Time.deltaTime * speed;
26 float scale = 1f;
27 Vector3 origScale = go.transform.localScale;
28 while(t < Mathf.PI / 2) {
29 t += Time.deltaTime * speed;
30 scale = endScale * Mathf.Sin(t);
31 go.transform.localScale = new Vector3(scale,scale,scale);
32 yield return null;
33 }
34 go.transform.localScale = new Vector3(endScale, endScale, endScale);
35 go.tag = "Ready";
36 }
37
38 public IEnumerator IEScaleOut(float startAfter, GameObject go, float speed) {
39 yield return IEScaleOutBase(startAfter, go, speed);
40 Destroy(go);
41 }
42
43 public IEnumerator IEScaleOut(float startAfter, GameObject go, float speed, Action callback) {
44 yield return IEScaleOutBase(startAfter,go,speed);
45 callback();
46 Destroy(go);
47 }
48
49 IEnumerator IEScaleOutBase(float startAfter, GameObject go, float speed) {
50 yield return new WaitForSeconds(startAfter);
51
52 float t = Time.deltaTime * speed;
53 float scale = 1f;
54 Vector3 origScale = go.transform.localScale;
55 t = Mathf.PI / 2f;
56 while(t < Mathf.PI) {
57 t += Time.deltaTime * speed;
58 scale = 1 * Mathf.Sin(t);
59 go.transform.localScale = origScale * scale;
60 yield return null;
61 }
62 }
63 }